package com.order.code.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.code.domain.OrderCode;
import com.order.code.service.IOrderCodeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 桌码管理Controller
 * 
 * @author huhu
 * @date 2020-08-19
 */
@Controller
@RequestMapping("/order/code")
public class OrderCodeController extends BaseController
{
    private String prefix = "order/code";

    @Autowired
    private IOrderCodeService orderCodeService;

    @RequiresPermissions("order:code:view")
    @GetMapping()
    public String code()
    {
        return prefix + "/code";
    }

    /**
     * 查询桌码管理列表
     */
    @RequiresPermissions("order:code:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderCode orderCode)
    {
        startPage();
        List<OrderCode> list = orderCodeService.selectOrderCodeList(orderCode);
        return getDataTable(list);
    }

    /**
     * 导出桌码管理列表
     */
    @RequiresPermissions("order:code:export")
    @Log(title = "桌码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderCode orderCode)
    {
        List<OrderCode> list = orderCodeService.selectOrderCodeList(orderCode);
        ExcelUtil<OrderCode> util = new ExcelUtil<OrderCode>(OrderCode.class);
        return util.exportExcel(list, "code");
    }

    /**
     * 新增桌码管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存桌码管理
     */
    @RequiresPermissions("order:code:add")
    @Log(title = "桌码管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderCode orderCode)
    {
        return toAjax(orderCodeService.insertOrderCode(orderCode));
    }

    /**
     * 修改桌码管理
     */
    @GetMapping("/edit/{deskId}")
    public String edit(@PathVariable("deskId") Long deskId, ModelMap mmap)
    {
        OrderCode orderCode = orderCodeService.selectOrderCodeById(deskId);
        mmap.put("orderCode", orderCode);
        return prefix + "/edit";
    }

    /**
     * 修改保存桌码管理
     */
    @RequiresPermissions("order:code:edit")
    @Log(title = "桌码管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderCode orderCode)
    {
        return toAjax(orderCodeService.updateOrderCode(orderCode));
    }

    /**
     * 删除桌码管理
     */
    @RequiresPermissions("order:code:remove")
    @Log(title = "桌码管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderCodeService.deleteOrderCodeByIds(ids));
    }
}
